package cn.iocoder.yudao.module.famous.doctor.service.famNoticeClose;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.famous.doctor.controller.app.famNoticeClose.vo.*;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.famNoticeClose.FamNoticeCloseDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.famous.doctor.convert.famNoticeClose.FamNoticeCloseConvert;
import cn.iocoder.yudao.module.famous.doctor.dal.mysql.famNoticeClose.FamNoticeCloseMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.famous.doctor.enums.ErrorCodeConstants.*;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;

/**
 * 中医-公告用户关闭 Service 实现类
 *
 * @author 档案
 */
@Service
@Validated
public class FamNoticeCloseServiceImpl implements FamNoticeCloseService {

    @Resource
    private FamNoticeCloseMapper famNoticeCloseMapper;

    @Override
    public Long createFamNoticeClose(AppFamNoticeCloseCreateReqVO createReqVO) {
        // 插入
        FamNoticeCloseDO famNoticeClose = FamNoticeCloseConvert.INSTANCE.convert(createReqVO);
        famNoticeCloseMapper.insert(famNoticeClose);
        // 返回
        return famNoticeClose.getId();
    }

    @Override
    public void updateFamNoticeClose(AppFamNoticeCloseUpdateReqVO updateReqVO) {
        // 校验存在
        validateFamNoticeCloseExists(updateReqVO.getId());
        // 更新
        FamNoticeCloseDO updateObj = FamNoticeCloseConvert.INSTANCE.convert(updateReqVO);
        famNoticeCloseMapper.updateById(updateObj);
    }

    @Override
    public void deleteFamNoticeClose(Long id) {
        // 校验存在
        validateFamNoticeCloseExists(id);
        // 删除
        famNoticeCloseMapper.deleteById(id);
    }

    private void validateFamNoticeCloseExists(Long id) {
        if (famNoticeCloseMapper.selectById(id) == null) {
            throw exception(FAM_NOTICE_CLOSE_NOT_EXISTS);
        }
    }

    @Override
    public FamNoticeCloseDO getFamNoticeClose(Long id) {
        return famNoticeCloseMapper.selectById(id);
    }

    @Override
    public List<FamNoticeCloseDO> getFamNoticeCloseList(Collection<Long> ids) {
        if (CollUtil.isEmpty(ids)) {
            return ListUtil.empty();
        }
        return famNoticeCloseMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<FamNoticeCloseDO> getFamNoticeClosePage(AppFamNoticeClosePageReqVO pageReqVO) {
        return famNoticeCloseMapper.selectPage(pageReqVO);
    }

    @Override
    public List<FamNoticeCloseDO> getFamNoticeCloseList(AppFamNoticeCloseExportReqVO exportReqVO) {
        return famNoticeCloseMapper.selectList(exportReqVO);
    }

}
